package tech.tuister.cninfo.download;

import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tech.tuister.cninfo.download.api.AnnouncementQueryAPI;

import java.util.Scanner;

@SpringBootApplication
public class CninfoDownloader implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(CninfoDownloader.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        if (args != null && args.length > 0) {
            for (String arg : args) {
                try {
                    AnnouncementQueryAPI.download(arg);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return;
        } else {
            System.out.println("请输入股票代码：");
            Scanner scanner = new Scanner(System.in);
            String line = scanner.nextLine();
            AnnouncementQueryAPI.download(StringUtils.stripToEmpty(line));
        }

        System.out.println("下载完成！保存路径为" + AnnouncementQueryAPI.BASE_DIR);
    }
}
